package com.jp.knowledge.adapter.attention;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.model.attention.CompanyListModel;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;

import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/3/17.
 */

public class AttentionGroupAdapter extends RecycleVAdapter<CompanyListModel.ListBean> {

    public AttentionGroupAdapter(Context context, @NonNull List<CompanyListModel.ListBean> list) {
        super(context, list);
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.attention_company_item;
    }

    @Override
    public void onBind(RecycleVHolder holder, int position) {
        CompanyListModel.ListBean data = getData(position);

        if(data.getType() != 2) {
            holder.setTextView(R.id.name, getData(position).getTitle());
        } else{
            String mainText = "";
            if(data.getDepaName() != null && data.getDepaName().trim().length() > 0)
                mainText += data.getDepaName();
            if(data.getClassName() != null && data.getClassName().trim().length() > 0)
                mainText += ("(" + data.getClassName() + ")");
            if(mainText.trim().length() > 0 && data.getTitle() != null && data.getTitle().trim().length() > 0)
                mainText += ("\n" + data.getTitle());
            holder.setTextView(R.id.name, mainText);
        }

        if(getData(position).getUpdate() == 1)
            holder.get(R.id.red_dot).setVisibility(View.VISIBLE);
        else
            holder.get(R.id.red_dot).setVisibility(View.GONE);
        TextView desc = holder.getTextView(R.id.desc);
        if("organizeGroup".equals(getData(position).getId())){
            desc.setText("单击加入你的组织");
            desc.setTextColor(mContext.getResources().getColor(R.color.orange));
            desc.setTextSize(TypedValue.COMPLEX_UNIT_PX, mContext.getResources().getDimension(R.dimen.min_font_12));
            desc.setVisibility(View.VISIBLE);
        } else if(getData(position).getAuditState() != 1){
            desc.setText("加入审核中，暂时无法看");
            desc.setTextColor(mContext.getResources().getColor(R.color.orange));
            desc.setTextSize(TypedValue.COMPLEX_UNIT_PX, mContext.getResources().getDimension(R.dimen.min_font_12));
            desc.setVisibility(View.VISIBLE);
        } else{
            desc.setVisibility(View.GONE);
        }
        if(getData(position).getAuditState() != 1)
            holder.get(R.id.right_img).setVisibility(View.GONE);
        else
            holder.get(R.id.right_img).setVisibility(View.VISIBLE);
    }
}
